﻿using Microsoft.Extensions.Diagnostics.HealthChecks;

namespace HealthCheck.Api.HealthChecks;

public class ExampleCustomHealthCheck : IHealthCheck
{
	private static readonly Random Random = new Random();
    
	public Task<HealthCheckResult> CheckHealthAsync(
		HealthCheckContext context, 
		CancellationToken cancellationToken = default)
	{
		// 模拟一些检查逻辑
		var isHealthy = Random.Next(5) > 0; // 80%的概率返回健康
		if (isHealthy)
		{
			return Task.FromResult(
				HealthCheckResult.Healthy("自定义健康检查正常"));
		}
		return Task.FromResult(
			HealthCheckResult.Unhealthy("自定义健康检查异常"));
	}
}
